package com.amtf.datafile2.core.txt;

import com.amtf.datafile2.DataException;
import com.amtf.datafile2.DataField;
import com.amtf.datafile2.core.std.StdDataFieldType;

public abstract class TxtFTBasic extends StdDataFieldType {

	protected int minLength = 0;
	protected int maxLength = -1;

	public TxtFTBasic(String name) {
		super(name);
	}

	public TxtFTBasic(String name, int minLength, int maxLength) {
		super(name);
		this.minLength = minLength;
		this.maxLength = maxLength;
	}

	public void validate(DataField value) throws DataException {
		if (maxLength >= 0) {
			int len = value.getValue().length();
			if (len < minLength || len > maxLength) {
				throw new DataException("Value length not match with definition: Length>= " + minLength + " and Length<= " + maxLength);
			}
		}
	}

	public int getMinLength() {
		return minLength;
	}

	public void setMinLength(int minLength) {
		this.minLength = minLength;
	}

	public int getMaxLength() {
		return maxLength;
	}

	public void setMaxLength(int maxLength) {
		this.maxLength = maxLength;
	}
}
